<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <!-- 分页组件 -->
  <div class="page">
    <div class="left">
      共{{ tableData.totalCount }}条记录&emsp;第 {{ pageIndex }}/{{
        tableData.totalPage
      }}页
    </div>
    <div class="right">
      <el-button type="success" @click="upData(-1)" :class="{ allow: pageIndex > 1 }">上一页</el-button>
      <el-button type="success"
        @click="upData(1)"
        :class="{ allow: pageIndex < tableData.totalPage }"
      >
        下一页
      </el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tableData: {
      required: true,
      type: Object
    },
    pageIndex: {
      required: true,
      type: Number
    }
  },
  methods: {
    upData (num) {
      if (
        this.pageIndex + num > 0 &&
        this.pageIndex + num <= this.tableData.totalPage
      ) {
        this.$emit('change', num)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.page {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80px;
  color: #dbdfe5;
  font-size: 16px;
  .right {
    display: flex;
    justify-content: space-around;
    width: 200px;
    margin-right: 10px;
    div {
      width: 70px;
      height: 32px;
      background-color: #edf0f9;
      border-radius: 3px;
      text-align: center;
      line-height: 32px;
      cursor: not-allowed;
      &.allow {
        background-color: #d5ddf8;
        color: #666;
        cursor: pointer;
      }
    }
  }
}
</style>
